feat: add mask() method to input field components for masking library integration#161
Draft
Copilot wants to merge 10 commits into
Draft
feat: add mask() method to input field components for masking library integration#161Copilot wants to merge 10 commits into
Copilot wants to merge 10 commits into
Conversation
… integration - Add mask(callback) method to SmarkField (via input.type.js): - Changes <input> type to "text" for non-text inputs (required by iMask.js etc.) - Stores original type in _originalType for reference - Calls callback(targetFieldNode) and stores result as _maskInstance - Delegates to inner field for singletons, returns `me` for chaining - Update _setTargetFieldValue() to dispatch "input" event when mask is active, so masking libraries re-process the new value on programmatic import() - Update export() to use _maskInstance.unmaskedValue when available, so derived types (number, date, etc.) still parse/return the correct semantic type - Add comprehensive tests in test/mask.tests.js (13 scenarios) Agent-Logs-Url: https://github.com/bitifet/SmarkForm/sessions/72c9bcc2-72c5-42a0-8d32-9fe27015b3da Co-authored-by: bitifet <1643647+bitifet@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
bitifet
April 17, 2026 23:21
View session
- Primary credit card example showing space-separated 4-digit groups - Price example demonstrating number field type with decimal/thousands separators - Singleton masking pattern with inner field delegation - _originalType restoration for native HTML5 input behavior - Validation integration using mask library events - Updated AGENTS.md with masking feature details
…sages - Add deep isSerializable() validation in setNodeOptions that checks for functions, symbols, undefined, non-finite numbers, and circular references - Throw renderError(INVALID_OPTIONS_OBJECT) instead of cryptic JSON.stringify errors - Convert field_masking.md static code blocks to interactive sampletabs playgrounds
- Restore original general tests (document loaded, focus behavior, default values focus race, basic introspection) - Add new tests for options serialization validation (cyclic refs, functions) - These validate the INVALID_OPTIONS_OBJECT renderError behavior
- Remove 'undefined' check from isSerializable() — JSON.stringify silently drops undefined property values, so they are serializable - Guard getPath() against unset parents (called during construction when renderError is thrown before parents is initialized) - Update masking docs: replace 'restores original type' with 'masking is permanent' to match current implementation
…try/catch - Resolve string selectors (e.g., '#payment') to DOM nodes in the SmarkForm constructor so string-based instantiation works - Remove the debugging try/catch wrapper from setNodeOptions — the isSerializable pre-check throws clear errors that propagate naturally through the constructor - Update validation tests to match new error behavior
…ix credit card blocks, add tests=false
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a public
.mask(callback)method to SmarkForm field components that provides a clean integration scaffold for input-masking libraries (like iMask.js) without adding any hard dependency.Changes
src/types/input.type.jsmask(callback)method (added to theinputclass, inherited bynumber,date,time,datetime-local,color, etc.):<input type>to"text"for any non-text input, because masking libraries like iMask.js requiretype="text". The original type is preserved in_originalType.callback(targetFieldNode)with the raw DOM element as the sole argument — this is the integration point where the caller attaches iMask or any other library._maskInstance._maskInstancelives whereexport()reads it).thisfor chaining._setTargetFieldValue()updated:inputevent on the element when a mask instance is active. This allows masking libraries to re-process the value whenimport()is called programmatically.export()updated:_maskInstance.unmaskedValueis defined, uses it as the raw value instead ofnodeFld.value. This ensures that derived types (number,date,time, etc.) receive the raw unmasked string and can still apply their own semantic type conversion (e.g.Number("1234.56")→1234.56rather thanNumber("1,234.56")→NaN).test/mask.tests.js(new)13 Playwright test cases covering:
_originalTypeis stored correctlymask()returnsthisfor chainingexport()usesunmaskedValuewhen providednumberafter maskingnodeFld.valuewhen mask has nounmaskedValue(or returns null)_maskInstancelands on the inner fieldimport()dispatchesinputevent on masked fields (and does NOT dispatch it on unmasked fields)Usage example (iMask.js)
Testing
All 284 existing tests continue to pass. All 13 new mask tests pass.